package com.icetec.iceintel.netrequest;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.support.v7.internal.widget.ThemeUtils;
import android.util.Log;

import com.icetec.R;
import com.icetec.iceintel.framework.AppApplication;
import com.icetec.iceintel.model.Scheme;
import com.icetec.iceintel.model.UserConfig;

/**
 * Created by amo on 2015/2/3.
 * 统一资源分配器，用以对不同图片的切换
 * 设备的图片，策略的图片都有不同的日夜模式，暂用代码去切换
 */
public class UniResAllocator {

  //灯具图标分配器
    static  public Drawable getResIDbyType(String type,Boolean isActive) {

        //从这里起是黑夜的灯光资源


        if (AppApplication.userConfig.getDaynightSchema().equals(UserConfig.CONTROL_NIGHT)) {

            if (type == null) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_on_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_off_night);

                }


            }

     //       Log.i("调用图片分配", type);

            if (type.equals(InstrutionConstant.DdevicesType_normallight)) {


                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.normal_light_active_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.normal_light_icon_unactive_night);

                }

            } else if (type.equals(InstrutionConstant.DdevicesType_toplight)) {


                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_on_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_off_night);

                }


            }
            else if (type.equals(InstrutionConstant.DdevicesType_bulb)) {


                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.bulb_icon_active_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.bulb_icon_unactive_night);

                }


            }

            else if (type.equals(InstrutionConstant.DdevicesType_groupControl)) {


                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lightlist_item_group_icon_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lightlist_item_group_icon_unactive);

                }
            }

            else {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_on_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_off_night);

                }

            }

        }

        //从这里起是白天的灯光资源

        else{

            if (type == null) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_on);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_off);

                }


            }

            Log.i("调用图片分配", type);

            if (type.equals(InstrutionConstant.DdevicesType_normallight)) {


                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.normal_light_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.normal_light_icon_unactive);

                }

            } else if (type.equals(InstrutionConstant.DdevicesType_toplight)) {


                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_on);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_off);

                }


            }

            else if (type.equals(InstrutionConstant.DdevicesType_bulb)) {


                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.bulb_icon_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.bulb_icon_unactive);

                }


            }

            else if (type.equals(InstrutionConstant.DdevicesType_groupControl)) {


                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lightlist_item_group_icon_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lightlist_item_group_icon_unactive);

                }


            }
            else {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_on);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.lighticon_off);

                }

            }

        }


    }

  //模式图标分配器
    static public Drawable getSchemeResIDbyType(String type,Boolean isActive) {


        //夜间模式
        if (AppApplication.userConfig.getDaynightSchema().equals(UserConfig.CONTROL_NIGHT)) {

            if (type == null) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_home_active_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_home_unactive_night);

                }


            }


            if (type.equals(Scheme.SchemeTypeWORK)) {
                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_work_active_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_work_unactive_night);

                }

            } else if (type.equals(Scheme.SchemeTypeSLEEP)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_sleep_active_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_sleep_unactive_night);

                }

            } else if (type.equals(Scheme.SchemeTypeRELAX)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_releax_active_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_releax_unactive_night);

                }

            } else if (type.equals(Scheme.SchemeTypeDIET)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_diet_active_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_diet_unactive_night);

                }

            } else if (type.equals(Scheme.SchemeTypeMOVIE)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_movie_active_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_movie_unactive_night);

                }

            } else if (type.equals(Scheme.SchemeTypeREAD)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_read_active_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_read_unactive_night);

                }

            } else if (type.equals(Scheme.SchemeTypeAll)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.btn_all_on_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.btn_all_off_night);

                }

            }
            else {


                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_work_active_night);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_work_unactive_night);

                }

            }
        }

        //白天模式
        else {

            if (type == null) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_home_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_home_unactive);

                }


            }

            if (type.equals(Scheme.SchemeTypeWORK)) {
                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_work_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_work_unactive);

                }

            } else if (type.equals(Scheme.SchemeTypeSLEEP)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_sleep_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_sleep_unactive);

                }

            } else if (type.equals(Scheme.SchemeTypeRELAX)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_releax_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_releax_unactive);

                }

            } else if (type.equals(Scheme.SchemeTypeDIET)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_diet_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_diet_unactive);

                }

            } else if (type.equals(Scheme.SchemeTypeMOVIE)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_movie_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_movie_unactive);

                }

            } else if (type.equals(Scheme.SchemeTypeREAD)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_read_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_read_unactive);

                }

            } else if (type.equals(Scheme.SchemeTypeAll)) {

                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.btn_all_on);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.btn_all_off);

                }

            }
            else {


                if (isActive) {
                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_work_active);

                } else {

                    return AppApplication.getShareInstance().getResources().getDrawable(R.drawable.scheme_icon_work_unactive);

                }

            }

        }

    }


}
